<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axios实例对象</title>
    <link crossorigin="anonymous" href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
</head>
<body>

    <script>

        //   const posts=axios.create({
        //       baseURL:'http://localhost:3000',
        //       timeout:2000
        //   });

        //   //console.log(posts);
          
        //   posts({
        //     url:'posts',
        //     method:"get"
        //   }).then(response=>{
        //      console.log(response);
        //   });

        //   console.log(res1);


        //   const others=axios.create({
        //       baseURL:'http://ajax-base-api-t.itheima.net',
        //       timeout:2000
        //   });

        //   //console.log(others);

        //   others({
        //     url:"api/getbooks",
        //     method:"get"
        //   }).then(response=>{
        //     console.log(response);
        //   });



        window.onload=async function(){
            
            const posts=axios.create({
                baseURL:'http://localhost:3000',
                timeout:2000
            });

            const res1= await posts({
                url:'posts',
                method:"get"
            });

            console.log(res1);

            const other=await axios.create({
                baseURL:'http://ajax-base-api-t.itheima.net',
                timeout:2000
            });

            const res2=await other({
                url:'api/getbooks',
                method:'get'
            });

            console.log(res2);
        }

    </script>
</body>
</html>